	var setting = {
		view: {
			showIcon: false,
			selectedMulti: false
		},
		data: {
			simpleData: {
				enable: true
			}
		}
	};
	$(function(){
		$('#menuform').validate({
			rules: {
				sort: {
					number: true
				}
			}
		});
		$("#menuSubmit").click(function(){
			if(!$('#menuform').valid())
				return false;
			$.ajax({
				type: 'post',
				data:$('#menuform').serialize(),
				url: baselocation+"/system/menu/add",
				success: function(result){
					if(result.code == 0) {
						var successMsg = "";
						if($('#menuId').val() == "") {
							successMsg = "新增菜单成功";
						}else{
							successMsg = "修改菜单成功";
						}
						
						layer.msg(successMsg, {
							icon : 1,
							time : 1000
						}, function() {
							window.parent.location.reload(); // 刷新父页面
						});
					}else {
						layer.msg(result.message, {
							icon : 2,
							time : 1000
						});
					}
				}
			});
			return false;
		})
	});
	// 保存上级菜单
	function saveParentMenu(){
		var nodes = $.fn.zTree.getZTreeObj("menuTree").getSelectedNodes();
		if(nodes[0].id != $('#menuId').val()){
			$('#parentId').val(nodes[0].id);
			$('#parentName').val(nodes[0].name);
			// 隐藏弹窗
			$('#menuModal').modal('hide');
		}else{
			layer.alert('不能选择当前菜单');
		}
	}
	// 清空上级菜单
	function clearParentMenu(){
		$('#parentId').val('');
		$('#parentName').val('');
	}
	// 显示弹窗
	function showMenu(){
		// 加载菜单的树状结构
		$.ajax({
			type: 'post',
			data:{"menuType":1},
			url: baselocation+"/system/menu/menuList",
			success: function(result){
				$.fn.zTree.init($("#menuTree"), setting, result.data);
			}
		});
		$('#menuModal').modal('show');
	}
	